<div class="page">
    <div class="menu">
		<?php include('modules/members/dashboard.php');?>
    </div>
    <div class="persons">
    <?php
        if($_SESSION['user'] != "admin"){
            echo '<h2 align="center" style="color:red; margin-top: 10%;">คุณไม่ใช่ผู้ดูแลระบบ ไม่มีสิทธิ์ในการเพิ่มพนักงาน.</h2>';
            die();
        }
    ?>
    <?php if(isset($_GET['action']) && $_GET['action'] == "update"){
        $sql = 'UPDATE customers SET store_name="'.$_POST['store'].'", name="'.$_POST['name'].'", address="'.$_POST['address'].'", tumbon="'.$_POST['tumbon'].'", amphur="'.$_POST['amphur'].'", province="'.$_POST['province'].'", postcode="'.$_POST['postcode'].'", mobile="'.$_POST['mobile'].'" WHERE id='.$_GET['id'];

        $q  = mysql_query($sql)or die(mysql_error());
        if($q){
            echo '<h1 style="color:green;font-size:40px;margin:65px 140px;">
                    <img src="css/images/customer.png">
                    แก้ไขข้อมูลเรียบร้อยแล้ว
                  </h1>';
        }
    }else{ ?>
    <form id="add_customer_form" action="?m=persons&p=edit_customer&action=update&id=<?php echo $_GET['id'];?>" method="post" >
    <?php
        $get = 'SELECT * FROM customers WHERE id='.$_GET['id'];
        $getq= mysql_query($get)or die(mysql_error());
        $getm= mysql_fetch_assoc($getq);
    ?>
        <table width="600" border="0" cellpadding="10" >
            <tbody>
                <tr>
                    <td width="200" align="right"><img src="css/images/customer.png" alt="เพิ่มพนักงาน" title="เพิ่มพนักงาน" /></td>
                    <td align="left"><h2>เพิ่มลูกค้า<h2></td>
                </tr>
                <tr>
                    <td align="right">ชื่อร้านค้า </td>
                    <td align="left"><input type="text" name="store" id="store" value="<?php echo $getm['store_name'];?>"/></td>
                </tr>
                <tr>
                    <td align="right">ชื่อ - นามสกุล </td>
                    <td align="left"><input type="text" name="name" id="name" value="<?php echo $getm['name'];?>"/></td>
                </tr>
                <tr>
                    <td align="right">ที่อยู่ </td>
                    <td align="left"><input type="text" name="address" id="address" value="<?php echo $getm['address'];?>"/></td>
                </tr>
                <tr>
                    <td align="right">ตำบล </td>
                    <td align="left"><input type="text" name="tumbon" id="tumbon" value="<?php echo $getm['tumbon'];?>"/></td>
                </tr>
                <tr>
                    <td align="right">อำเภอ </td>
                    <td><input type="text" name="amphur" id="amphur" value="<?php echo $getm['amphur'];?>"/></td>
                </tr>
                <tr>
                    <td align="right">จังหวัด </td>
                    <td align="left"><input type="text" name="province" id="province" value="<?php echo $getm['province'];?>"/></td>
                </tr>
                <tr>
                    <td align="right">รหัสไปรษณีย์ </td>
                    <td align="left"><input type="text" name="postcode" id="postcode" value="<?php echo $getm['postcode'];?>"/></td>
                </tr>
                <tr>
                    <td align="right">เบอร์โทรศัพท์ </td>
                    <td align="left"><input type="text" name="mobile" id="mobile" value="<?php echo $getm['mobile'];?>"/></td>
                </tr>
                <tr>
                    <td align="right"></td>
                    <td align="left">
                        <p style="margin-left:0px;margin-top:25px;" id="button">
                        	<a href="#" class="btn" style="font-size:25px;" id="edit_customer_btn" onClick="return false;">
                        	    <span>แก้ไข</span>
                            </a>
                            <span class="loading"></span>
                       	</p>
       	            </td>
                </tr>
            </tbody>
        </table>
    </form>
    <?php } ?>
    </div>
</div>

